﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Models;
using BLL;
using System.Data.Entity;
namespace CMS项目.Areas.HouTaiArea.Controllers
{
    public class IndexController : Controller
    {
        BLLCMS_Article BLLCMS_Article = new BLLCMS_Article();
        // GET: HouTaiArea/Index
        public ActionResult Index()
        {
            return View();
        }
        [HttpPost]
        public ActionResult Index(string Uname, string upwd)
        {
            using (var wdb = new KQCMS())
            {
                var list = wdb.CMS_User.Where(u => u.Uname.Equals(Uname) && u.upwd.Equals(upwd)).Count();
                if (list > 0)
                {
                    return Content("alter(登陆成功)");
                    //return RedirectToAction("add.cshtml");
                }
                else
                {
                    return View();
                }
            }
        }

        public ActionResult add()
        {
            return View();
        }
        public ActionResult del()
        {
            return View();
        }
        public ActionResult login()
        {
            return View();
        }
        //分页查询所有的评论
        [HttpGet]
        public ActionResult GetView_CommentAU()
        {
            //var list = (BLL_View_CommentAU.GetView_CommentAUs(1, 3, null, null).Data).ToList();
            //var count = BLL_View_CommentAU.GetView_CommentAUs(1, 3, null, null).Count;
            //ViewBag.count = count;
            return View(/*list*/);
            //return Json(BLL_View_CommentAU.GetView_CommentAUs(1, 3, null, null), JsonRequestBehavior.AllowGet);
        }
        //分页查询所有的评论
        [HttpPost]
        public ActionResult GetView_CommentAU(int PageIndex, int PageSize,  string title)
        {
            return Json(BLL_View_CommentAU.GetView_CommentAUs(PageIndex, PageSize,  title));
        }
        //添加评论
        [HttpGet]
        public ActionResult AddCMS_Comment()
        {
            using (var db = new KQCMS())
            {
                ViewBag.Article = new SelectList(db.CMS_Article.ToList(), "aid", "title");
                ViewBag.User = new SelectList(db.CMS_User.ToList(), "Uid", "nname");
            }
            return View();
        }
        //添加评论
        public ActionResult AddCMS_Comment(CMS_Comment cm)
        {
            int count = BLL_View_CommentAU.AddCMS_Comment(cm);
            if (count > 0)
                return Content("alert('成功')");
            else
                return Content("alert('失败')");
        }

        //删除评论
        [HttpPost]
        public bool DeleteCMS_Comment(int cmid)
        {
            int count = BLL_View_CommentAU.DeleteID(cmid);
            if (count > 0)
                return true;
            else
                return false;
        }

        /// <summary>
        /// 分页查询所有的关键字
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public ActionResult GetCMS_Keyword()
        {
            return View();
        }
        //分页查询所有的关键字
        [HttpPost]
        public ActionResult GetCMS_Keyword(int PageIndex, int PageSize, string keyword)
        {
            return Json(BLL_CMS_Keyword.GetCMS_Keyword(PageIndex, PageSize, keyword));
        }
        /// <summary>
        /// 添加关键字
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public ActionResult AddCMS_Keyword()
        {
            return View();
        }
        [HttpPost]
        public bool AddCMS_Keyword(CMS_Keyword kd)
        {
            int count = BLL_CMS_Keyword.AddCMS_Keyword(kd);
            if (count > 0)
                return true;
            else
                return false;
        }

        //根据kid删除关键字
        [HttpPost]
        public bool DeleteCMS_Keyword(int kid)
        {
            int count = BLL_CMS_Keyword.DeleteID(kid);
            if (count > 0)
                return true;
            else
                return false;
        }

        //根据kid查询跳转
       
        [HttpGet]
        public ActionResult UpdateCMS_Keyword()
        {
            
            return View();
        }
        [HttpPost]
        public ActionResult UpdateCMS_Keyword(CMS_Keyword kd)
        {
            return Json(BLL_CMS_Keyword.UpdateCMS_Keyword(kd));
        }
        [HttpPost]
        public ActionResult UpdateCMS_Keywords(int kid)
        {
           return Json(BLL_CMS_Keyword.SelectID(kid));
        }

        [HttpGet]
        public ActionResult Updateaa()
        {
            //int count = BLL_CMS_Keyword.UpdateCMS_Keyword(kd);
            return View();
        }
        [HttpPost]
        public ActionResult Updateaa(CMS_Keyword kd)
        {
            //int count = BLL_CMS_Keyword.UpdateCMS_Keyword(kd);
            return Json( BLL_CMS_Keyword.UpdateCMS_Keyword(kd));
            
        }

        public ActionResult SelectPage(int? pageindex, int? pagesize)
        {
            return Json(BLLCMS_Article.GetPageCMS_Articles((int)pageindex, (int)pagesize, null), JsonRequestBehavior.AllowGet);
        }
        [HttpPost]
        public ActionResult SelectPage(int? pageindex, int? pagesize, string aid)
        {
            return Json(BLLCMS_Article.GetPageCMS_Articles((int)pageindex, (int)pagesize, aid));
        }
        [HttpPost]
        public ActionResult DelectArticle(int? id)
        {
            return Json(BLLCMS_Article.DelectArticle(id));
        }
    }
}